package com.easy.web.controller.merchants;

import com.easy.common.core.R;
import com.easy.merchants.pojo.PublicPraise;
import com.easy.merchants.service.IPublicPraiseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 口碑控制器
 *
 * @author RuoYu
 * @date 2022/12/01
 */
@RestController
@RequestMapping
@Api(tags = "口碑控制器")
public class PublicPraiseController {
    @Autowired
    private IPublicPraiseService publicPraiseService;


    /**
     * 更新口碑
     *
     * @param publicPraise 口碑实体
     * @return {@link R}
     */
    @PutMapping("/pp/update")
    @ApiOperation(value = "更新口碑")
    @ApiImplicitParam(name = "publicPraise", value = "口碑实体", required = true)
    public R updatePublicPraise(@RequestBody PublicPraise publicPraise) {
        publicPraiseService.updateEvaluate(publicPraise);
        return R.success();
    }

    /**
     * 获得口碑
     *
     * @param id 房东id
     * @return {@link R}
     */
    @GetMapping("pp/get")
    @ApiOperation(value = "获得口碑")
    @ApiImplicitParam(name = "id", value = "房东id", dataTypeClass = Integer.class, required = true)
    public R getPublicPraise(Long id) {
        List<Double> evaluate = publicPraiseService.getEvaluate(id);
        System.out.println(evaluate + "------------------");
        return R.success(evaluate);
    }
}
